<?php

namespace app\admin\controller;

use app\AdminBaseController;
use app\admin\model\Admin;

class Login extends AdminBaseController
{
    protected function initialize(){}
    /**
     * 后台登录
     */
    public function login(){
        $user = session('admin');
        if(!empty($user)) $this->success('登录成功，系统自动跳转至首页', '../Index/index');
        if($this->request->post()){
            (new Admin())->checkUser();
        }
        return view('login');
    }
    /**
     * 退出登录
     * @return void
     */
    public function logout(){
        session(null);
        $this->success('退出登录成功，页面自动跳转中', '../Login/login');
    }

    /**
     * 修改管理员自身密码
     */
    public function updatePwd(){
        $admin = session('admin');
        if($this->request->post()){
            (new Admin())->updatePwd();
        }
        return view('updatePwd',["admin"=>$admin]);
    }
}